package com.tianhui.consignortwofei.mvp.ui.activity.audit.vehicle;

import android.text.TextUtils;
import android.view.View;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.entity.PictureInfo;
import com.fgs.common.widget.TabSwitchView;
import com.fgs.common.widget.itemView.InputItemView;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.constant.KeyValue;
import com.tianhui.consignortwofei.mvp.model.enty.VehicleInfo;

import butterknife.BindView;

public class VehicleStatementAuditActivity extends BaseVehicleAuditActivity {

    @BindView(R.id.activity_vehicle_statement_audit_plateNumberInputItemView)
    InputItemView mPlateNumberInputItemView;
    @BindView(R.id.activity_vehicle_statement_audit_plateNumberTowedInputItemView)
    InputItemView mPlateNumberTowedInputItemView;
    @BindView(R.id.activity_vehicle_statement_audit_ownerInputItemView)
    InputItemView mOwnerInputItemView;
    @BindView(R.id.activity_vehicle_statement_audit_modelInputItemView)
    InputItemView mModelInputItemView;
    @BindView(R.id.activity_vehicle_statement_audit_attachTabSwitchView)
    TabSwitchView mAttachTabSwitchView;
    @BindView(R.id.activity_vehicle_statement_audit_remarkInputItemView)
    InputItemView mRemarkInputItemView;
    private String mStatementImageId;
    private String mAttachStatus;

    @Override
    public int getLayoutId() {
        return R.layout.activity_vehicle_statement_audit;
    }

    @Override
    public CommonPresenter createPresenter() {
        return null;
    }

    @Override
    public CommonView createView() {
        return null;
    }

    @Override
    public CommonFragment createFragment() {
        return null;
    }

    @Override
    public void changePictureSuccess(PictureInfo pictureInfo) {
        mStatementImageId = pictureInfo.id;
    }

    @Override
    protected void showOperateView(int operate) {
        if (operate == KeyValue.KEY_EDIT_OPERATE) {
            mSaveButton.setVisibility(View.VISIBLE);
            mNextButton.setVisibility(View.GONE);
        } else if (operate == KeyValue.KEY_AUDIT_OPERATE) {
            mSaveButton.setVisibility(View.GONE);
            mNextButton.setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void showVehicleInfo(VehicleInfo info) {
        mPlateNumberInputItemView.setContent(info.vehiclenum);
        mPlateNumberTowedInputItemView.setContent(info.railerehicletvplatenumber);
        mOwnerInputItemView.setContent(info.owner);
        mModelInputItemView.setContent(info.brandmodel);
        mRemarkInputItemView.setContent(info.remark);
        loadPicture(info.imgmanagedimage, false);
        if (!TextUtils.isEmpty(info.ismanaged) && info.ismanaged.equals("1")) {
            mAttachTabSwitchView.setDefaultSelection(0);
        } else {
            mAttachTabSwitchView.setDefaultSelection(1);
        }
        mStatementImageId = info.managedimage;
        mAttachStatus = info.ismanaged;
    }

    @Override
    public VehicleInfo getSaveInfo() {
        mVehicleInfo.managedimage = mStatementImageId;
        mVehicleInfo.ismanaged = mAttachStatus;
        String remark = mRemarkInputItemView.getContent();
        mVehicleInfo.remark = remark;
        return mVehicleInfo;
    }

    @Override
    public void nextAudit() {
        VehicleInfo vehicleInfo = getSaveInfo();
        if (vehicleInfo != null) {
            vehicleInfo.isaudit = 1;
            requestVehicleInfoSaveAndAudit(vehicleInfo);
        }
    }


    @Override
    public void init() {
        super.init();
        mNextButton.setText("保存并审核通过");
        //是否挂靠
        mAttachTabSwitchView.setOnTabCheckedChangeListener(new TabSwitchView.OnTabCheckedChangeListener() {
            @Override
            public void onCheckedChanged(int position, String item, String value) {
                if (position == 0) {
                    mAttachStatus = "1";
                } else {
                    mAttachStatus = "0";
                }

            }
        });
    }
}
